<?php
/**
 * Created by PhpStorm.
 * User: 666
 * Date: 2020/4/3
 * Time: 16:24
 */
namespace App\Process;

use App\Consts\RedisKey;
use App\Middleware\AuthMiddleware;
use App\Model\LotteryOption;
use App\Model\LotteryRoomManager;
use App\Model\LotteryRoundsLog;
use App\Model\Order;
use App\Model\Pool;
use App\Model\Role;
use App\Model\SystemConfig;
use App\Model\Task;
use App\Model\TaskLog;
use App\Model\User;
use App\Model\UserOnlineStatistics;
use App\Utility\Register;
use App\Utility\Response;
use EasySwoole\Component\Process\AbstractProcess;
use EasySwoole\EasySwoole\Config;
use EasySwoole\EasySwoole\ServerManager;
use EasySwoole\RedisPool\Redis;

class RunProcess extends AbstractProcess
{



    protected function run($arg)
    {

//        go(function () {
//
//            Redis::defer('redis')->del(RedisKey::WS_USER_FD_HASH_LIST);
//
//            $role_ids = Role::create()->column('id');
//            foreach ($role_ids as $role_id) {
//                Redis::defer('redis')->set(RedisKey::user_authority_list($role_id), json_encode(AuthMiddleware::getInstance()->getAuthority($role_id)));
//            }
//
//        });


        $shield = Config::getInstance()->getConf('ipAccessCount.shield');
        //清除屏蔽Ip
        $timerId = \EasySwoole\Component\Timer::getInstance()->loop(3 * 1000, function () use ($arg,$shield) {
            Redis::defer('redis')->zRemRangeByScore(RedisKey::IP_PRISON,0,time()-$shield);

        },'time');



    }




    protected function onPipeReadable(\Swoole\Process $process)
    {
        /*
         * 该回调可选
         * 当有主进程对子进程发送消息的时候，会触发的回调，触发后，务必使用
         * $process->read()来读取消息
         */
    }

    protected function onShutDown()
    {
        /*
         * 该回调可选
         * 当该进程退出的时候，会执行该回调
         */
    }

    protected function onException(\Throwable $throwable, ...$args)
    {
        /*
         * 该回调可选
         * 当该进程出现异常的时候，会执行该回调
         */
    }
}